// pages/user/customerList/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pageSize: 1,
    pageNum: 10,
    keyword: "",
    dataList: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.getData()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  // 获取数据
  getData() {
    const self = this;
    console.log(this.data.pageNum)
    const data = {
      pageSize: this.data.pageSize,
      pageNum: this.data.pageNum,
      keyword: this.data.keyword,
    }
    wx.request({
      url: 'https://erp.yilestar.com/weapp/customer/pagequery',
      data,
      method:'post',
      success: (res) => {
        const datas = res.data.data;
        self.setData({
          dataList: datas.data
        })
      }
    })
  },

  // 监听输入关键词，并且搜索查询
  onChange(e) {
    const self = this;
    let keyword = e.detail;
    self.setData({
      keyword
    })
    clearTimeout(self.time);
    self.time = setTimeout(() => {
      self.getData()
    }, 1000)
  },

  // 选择客户
  handleSelect(e) {
    let name = e.currentTarget.dataset.name;
    let id = e.currentTarget.dataset.id;
    console.log(e.currentTarget.dataset)
    wx.setStorageSync("custName", name);
    wx.setStorageSync("custId", id);
    setTimeout(() => {
      wx.navigateBack({
        delta: 1
      })
    }, 500)

  }
})